package com.song.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.song.ssm.mapper.UserMapper;
import com.song.ssm.pojo.User;
import com.song.ssm.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/10/11
 * @Version 1.0
 **/
@Service
public class UserService implements IUserService {
    @Resource
    private UserMapper userMapper;


    @Override
    public List<User> findAll() {
        return this.userMapper.findAll();
    }

    @Override
    public boolean save(User user) {
        return this.userMapper.add(user)==1;
    }

    @Override
    public boolean delete(int id) {
        return this.userMapper.del(id) == 1;
    }

    @Override
    public PageInfo<User> pageUsers(int offset, int pagesize) {
        PageHelper.startPage(offset,pagesize);
        return new PageInfo<>(this.userMapper.findAll());
    }

    @Override
    public boolean update(User user) {
        return this.userMapper.update(user)==1;
    }

    @Override
    public boolean batch_del(String ids) {
        String [] arr= ids.split(",");
        return this.userMapper.batch_del(arr);
    }
}
